<template>
	<view class="page">
		<view class="ul" v-if="list.length>0">
			<view v-for="(item, index) in list" :key="index" :class="[index == 0 ? 'lic' : 'li']"
				@click="navback(item)">
				<view class="address">{{item.province}}{{item.city}}{{item.area}}</view>
				<view class="dis aic jcsb">
					<view class="detail">{{item.address}}</view>
					<view class="edit_box" @click.stop="goEdit(item)">
						<image src="/static/icon/icon_15.png" mode="widthFix" class="edit"></image>
					</view>
				</view>
				<view style="margin: 4rpx 0;">
					<text class="name">{{item.name}}</text>
					<text class="phone">{{item.phone}}</text>
					<text class="default" v-if="item.isDefault == 1">默认</text>
				</view>
			</view>
		</view>
		<view v-else class="none">暂无收货地址，快去新建一个吧</view>
		<view class="add" @click.stop="goAdd">新增收货地址</view>
	</view>
</template>

<script>
	import {
		receiptInformationList
	} from '@/api.js'
	export default {
		data() {
			return {
				index: 0,
				list: [],
				radiovalue1: '苹果',
			}
		},
		onShow() {
			this.init()
		},
		onLoad() {
			uni.$on('refreshData', (data) => {
				this.init(); // 刷新数据方法
			});
		},
		methods: {
			init() {
				this.getList()
			},
			async getList() {
				let res = await receiptInformationList()
				this.list = res.result
			},
			groupChange(n) {
				console.log('groupChange', n);
			},
			radioChange(n) {
				console.log('radioChange', n);
			},
			goEdit(item) {
				uni.navigateTo({
					url: '/pages/shop/address?item=' + JSON.stringify(item)
				})
			},
			goAdd() {
				uni.navigateTo({
					url: '/pages/shop/address'
				})
			},
			navback(item) {
				// let pages = getCurrentPages();
				// let prePage = pages[pages.length - 2]; //上一个页面
				// prePage.$vm["address"]({
				// 	name: "北京市",
				// 	id: 1
				// });
				uni.$emit('refreshData', item);
				uni.navigateBack()
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {
		background-color: #F6F6F6;
		min-height: 100vh;
		width: 750rpx;
	}

	.address {
		font-size: 28rpx;
		color: #666;
		margin: 4rpx 0;
	}

	.detail {
		font-size: 32rpx;
		color: #000;
		margin: 4rpx 0;
	}

	.edit_box {
		padding: 10rpx 20rpx;

		.edit {
			width: 40rpx;
		}
	}


	.name {
		font-size: 28rpx;
		color: #666;
	}

	.phone {
		font-size: 28rpx;
		color: #666;
		margin-left: 20rpx;
	}

	.default {
		font-size: 28rpx;
		color: #3DA591 !important;
		margin-left: 20rpx;
	}

	.lic {
		width: 690rpx;
		margin: 10rpx auto;
		// border-bottom: 1rpx solid #3DA591;
		padding-bottom: 10rpx;
		background: rgba(251, 228, 63, 0.04);

		padding: 10rpx 20rpx;
		box-sizing: border-box;
		color: #3DA591 !important;
		margin-top: 20rpx;
		border-radius: 6rpx;
		box-shadow: 0 2px 4px rgba(251, 228, 63, 0.16),
			0 3px 6px rgba(251, 228, 63, 0.12);

		.detail {
			font-size: 32rpx;
			color: #3DA591;
			margin: 4rpx 0;
		}
	}

	.li {
		width: 690rpx;
		margin: 10rpx auto;
		// border-bottom: 1rpx solid #666;
		padding-bottom: 10rpx;
		padding: 10rpx 20rpx;
		box-sizing: border-box;
		background: #fff;
		margin-top: 20rpx;
		border-radius: 6rpx;
		box-shadow: 0 2px 4px rgba(251, 228, 63, 0.2),
			0 3px 6px rgba(251, 228, 63, 0.15);

	}

	.ul {
		width: 750rpx;
		max-height: calc(100vh - 180rpx - 20rpx);
		overflow-y: scroll;
	}

	.add {
		position: fixed;
		bottom: 80rpx;
		width: 660rpx;
		left: 45rpx;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		background: rgba(251, 228, 63, 0.73);
		border-radius: 67rpx 67rpx 67rpx 67rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 40rpx;
		color: #FFFFFF;
	}

	.none {
		min-height: 50vh;
		padding-bottom: 50vh;
		width: 750rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #fff;
	}
</style>